/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package SessionBeans;

import Entities.Utilisateur;
import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Dell
 */
@Stateless
@LocalBean
public class Users {

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    @PersistenceContext(unitName = "PetriNetSimulator-ejbPU")
    private EntityManager em;

    public Users() {
    }

    public Utilisateur getLoginFromUser(String login) {
        Query query = em.createNamedQuery("Utilisateur.findByLogin");
        query.setParameter("login", login);
        return (Utilisateur) query.getSingleResult();
    }

    public List<Utilisateur> GetAllUsers() {
        Query query = em.createNamedQuery("Utilisateur.findAll");
        return query.getResultList();
    }
    

    public List<Utilisateur> authentification(String login) {

        Query query = em.createNamedQuery("Utilisateur.findByLogin");
        query.setParameter("login", login);
        return query.getResultList();
    }
    public void persist(Object object) {
        em.persist(object);
    }
}
